import {useEffect, useState} from "react";

export const useChannels = () => {
    const [channels, setChannels] = useState([]);
    const fetchChannels = async () => {
        try {
            const result = await fetch("http://geek.itheima.net/v1_0/channels")
            const {data: {channels}} = await result.json();
            setChannels(channels)
        } catch (error) {
            console.log(error)
        }
    }
    useEffect(() => {
        fetchChannels()
    }, [])
    return [channels]
}

export default useChannels;
